Array
and KeyedLinkedList
are two of the many subclasses of Collection
that can be used in a ScriptX program. Collections provide comprehensive behavior for groupings of objects. Array
and KeyedLinkedList
are prime representations of two categories of collection: those with explicit keys and those without. Collections are described in detail in Chapter 7, "Collections," and in the "Collections" chapter of ScriptX Components Guide.
#
):#(expression, expression, expression, expression, . . . )When the array construct is evaluated, each individual expression is also evaluated, in order, so that the resulting array contains the result of each of those expressions. Arrays themselves are instances of the class
Array
. Here are some examples of array literals:#(2, 4.2 + 5, "Fresno", 3 < 4, #(@doug, @jocelyn, @jim))
#(2, 9.19999694824219, "Fresno", true, #(@doug, @jocelyn, @jim))
#() -- empty array
#()
In some languages, all items in an array must be of the same type. The first example demonstrates that in ScriptX, members of an array can belong to different classes. The five members of this array belong to the classes ImmediateInteger
, ImmediateFloat
, StringConstant
, Boolean
, and Array
, respectively.
KeyedLinkedList
.#(key:value, key:value, key:value, . . . )In the keyed linked list literal, key-value pairs are separated by commas, with colons separating the key from the value. Like the array construct, all the expressions within the keyed list literal are evaluated before the instance of the
KeyedLinkedList
is created.The value part of a key-value pair can be any expression. To specify most complex expressions as the key part of the pair, you must specify that expression inside parentheses (and the result of that expression becomes the key itself). The following expressions can be used without parentheses as the key part of the key-value pair:
45
, "this or that"
, @nameMe
)
myArray[1]
, described in "Access to Members of Collections")
myRect.x1
, described in Chapter 3, "Working with Objects")
#(@fruit: "apple", @vegetable: "carrot", @legume: "kidney bean")
#(:) -- empty keyed list
#(1:"money", 2:"show", 3:"ready", 4:"go")
#( #(1,2,3):@oneToThree, #(4,5,6):@fourToSix, \
#(7,8,9,10):@sevenToTen) )
x := 1; y := 4
#( (x < y):@smallX, (x > y):@smallY )
#(true:@smallX, false:@smallY)
#("Bornstein","Agostino","Reiman","Jacobi") as SortedArray
#("Agostino", "Bornstein", "Jacobi", "Reiman") as SortedArray
Coercion is discussed in the section "Coercing Objects to Other Classes" on page 66, and again in the section "Coercing Between Collection Classes" on page 156.
This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.